/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.aptech.forms.nhanh;

import com.aptech.beans.Suppliers;
import com.aptech.dao.SupplierTypeManager;
import com.aptech.validate.CustomerValidator;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Anh Nguyen
 */
public class SupplierTypeList extends javax.swing.JFrame {

    private String flag = "";
    /**
     * Creates new form SupplierTypeList
     */
    public SupplierTypeList() throws Exception{
        initComponents();
        setLocationRelativeTo(null);
        loadData();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdSuppTypeList_InsertUpdate = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        jlblSuppTypeList_Name = new javax.swing.JLabel();
        jtfSuppTypeList_Name = new javax.swing.JTextField();
        jlblSuppTypeList_Description = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtaSuppTypeList_Description = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        jbtSuppTypeList_Submit = new javax.swing.JButton();
        jbtSuppTypeList_Reset = new javax.swing.JButton();
        jdSuppList_Notification = new javax.swing.JDialog();
        jLabel10 = new javax.swing.JLabel();
        jlblName = new javax.swing.JLabel();
        jlblStatus_Name = new javax.swing.JLabel();
        jlblDescription = new javax.swing.JLabel();
        jlblStatus_Description = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbSuppTypeList = new javax.swing.JTable();
        jbtInsert = new javax.swing.JButton();
        jbtUpdate = new javax.swing.JButton();
        jbtDelete = new javax.swing.JButton();

        jdSuppTypeList_InsertUpdate.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jdSuppTypeList_InsertUpdate.setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Segoe UI Light", 1, 14), new java.awt.Color(255, 0, 0))); // NOI18N

        jlblSuppTypeList_Name.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppTypeList_Name.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppTypeList_Name.setText("Name:");

        jtfSuppTypeList_Name.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtfSuppTypeList_Name.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtfSuppTypeList_NameActionPerformed(evt);
            }
        });

        jlblSuppTypeList_Description.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jlblSuppTypeList_Description.setForeground(new java.awt.Color(51, 0, 255));
        jlblSuppTypeList_Description.setText("Description:");

        jtaSuppTypeList_Description.setColumns(20);
        jtaSuppTypeList_Description.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jtaSuppTypeList_Description.setRows(5);
        jScrollPane2.setViewportView(jtaSuppTypeList_Description);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlblSuppTypeList_Name)
                    .addComponent(jlblSuppTypeList_Description))
                .addGap(61, 61, 61)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE)
                    .addComponent(jtfSuppTypeList_Name))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblSuppTypeList_Name)
                    .addComponent(jtfSuppTypeList_Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblSuppTypeList_Description))
                .addGap(34, 34, 34))
        );

        jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/029.png"))); // NOI18N

        jbtSuppTypeList_Submit.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtSuppTypeList_Submit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/003.png"))); // NOI18N
        jbtSuppTypeList_Submit.setText("Submit");
        jbtSuppTypeList_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSuppTypeList_SubmitActionPerformed(evt);
            }
        });

        jbtSuppTypeList_Reset.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtSuppTypeList_Reset.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/016.png"))); // NOI18N
        jbtSuppTypeList_Reset.setText("Reset");
        jbtSuppTypeList_Reset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtSuppTypeList_ResetActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jdSuppTypeList_InsertUpdateLayout = new javax.swing.GroupLayout(jdSuppTypeList_InsertUpdate.getContentPane());
        jdSuppTypeList_InsertUpdate.getContentPane().setLayout(jdSuppTypeList_InsertUpdateLayout);
        jdSuppTypeList_InsertUpdateLayout.setHorizontalGroup(
            jdSuppTypeList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdSuppTypeList_InsertUpdateLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addComponent(jbtSuppTypeList_Submit)
                .addGap(52, 52, 52)
                .addComponent(jbtSuppTypeList_Reset)
                .addGap(0, 62, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppTypeList_InsertUpdateLayout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jLabel9)
                .addGap(164, 164, 164))
        );
        jdSuppTypeList_InsertUpdateLayout.setVerticalGroup(
            jdSuppTypeList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppTypeList_InsertUpdateLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE)
                .addGroup(jdSuppTypeList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jdSuppTypeList_InsertUpdateLayout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(173, 173, 173))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdSuppTypeList_InsertUpdateLayout.createSequentialGroup()
                        .addGroup(jdSuppTypeList_InsertUpdateLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtSuppTypeList_Submit)
                            .addComponent(jbtSuppTypeList_Reset))
                        .addGap(97, 97, 97))))
        );

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel10.setForeground(new java.awt.Color(153, 0, 153));
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/031.png"))); // NOI18N
        jLabel10.setText("Notification");
        jLabel10.setToolTipText("");

        jlblName.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblName.setForeground(new java.awt.Color(255, 102, 102));
        jlblName.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblName.setText("Name:");

        jlblStatus_Name.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Name.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Name.setText("field");

        jlblDescription.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblDescription.setForeground(new java.awt.Color(255, 102, 102));
        jlblDescription.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jlblDescription.setText("Description:");

        jlblStatus_Description.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlblStatus_Description.setForeground(new java.awt.Color(102, 102, 102));
        jlblStatus_Description.setText("field");

        javax.swing.GroupLayout jdSuppList_NotificationLayout = new javax.swing.GroupLayout(jdSuppList_Notification.getContentPane());
        jdSuppList_Notification.getContentPane().setLayout(jdSuppList_NotificationLayout);
        jdSuppList_NotificationLayout.setHorizontalGroup(
            jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addGap(71, 71, 71)
                .addComponent(jLabel10)
                .addContainerGap(106, Short.MAX_VALUE))
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblDescription, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblName, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jlblStatus_Description, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jlblStatus_Name, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jdSuppList_NotificationLayout.setVerticalGroup(
            jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdSuppList_NotificationLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel10)
                .addGap(41, 41, 41)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblName, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Name))
                .addGap(48, 48, 48)
                .addGroup(jdSuppList_NotificationLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jlblDescription, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jlblStatus_Description))
                .addContainerGap(64, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Supplier Types Management");
        setIconImage(new ImageIcon(getClass().getResource("/com/image/icon.png")).getImage());

        jLabel1.setFont(new java.awt.Font("Segoe UI Light", 1, 24)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(255, 0, 0));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/037.png"))); // NOI18N
        jLabel1.setText("Supplier Types Management");

        jtbSuppTypeList.setFont(new java.awt.Font("Segoe UI Light", 0, 14)); // NOI18N
        jtbSuppTypeList.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Name", "Description"
            }
        ));
        jtbSuppTypeList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbSuppTypeList);

        jbtInsert.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtInsert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/026.png"))); // NOI18N
        jbtInsert.setText("Insert");
        jbtInsert.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtInsertActionPerformed(evt);
            }
        });

        jbtUpdate.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtUpdate.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/027.png"))); // NOI18N
        jbtUpdate.setText("Update");
        jbtUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtUpdateActionPerformed(evt);
            }
        });

        jbtDelete.setFont(new java.awt.Font("Segoe UI Light", 1, 14)); // NOI18N
        jbtDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/image/028.png"))); // NOI18N
        jbtDelete.setText("Delete");
        jbtDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 568, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(77, 77, 77)
                .addComponent(jbtInsert)
                .addGap(32, 32, 32)
                .addComponent(jbtUpdate)
                .addGap(34, 34, 34)
                .addComponent(jbtDelete)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 402, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(81, 81, 81))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jLabel1)
                .addGap(28, 28, 28)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtInsert)
                    .addComponent(jbtUpdate)
                    .addComponent(jbtDelete))
                .addGap(33, 33, 33))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

//    DefaultTableModel tableModel;
    /* Load data to table */
    DefaultTableModel tableModel;
    private void loadData(){
        tableModel = (DefaultTableModel) jtbSuppTypeList.getModel();
        tableModel.setRowCount(0);
        try {
            ResultSet resultSet = SupplierTypeManager.displayAllRows();
            while (resultSet.next()) {
                Vector vector = new Vector();
                vector.add(String.valueOf(resultSet.getInt(1)).trim());
                vector.add(resultSet.getString(2).trim());
                vector.add(resultSet.getString(3) == null ? "" : resultSet.getString(3).trim());
                tableModel.addRow(vector);
                System.out.println(resultSet.getInt(1) + resultSet.getString(2) + resultSet.getString(3));
            }
        } catch (Exception ex) {
            Logger.getLogger(SupplierTypeList.class.getName()).log(Level.SEVERE, null, ex);
        }
     }
    private void jtfSuppTypeList_NameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtfSuppTypeList_NameActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtfSuppTypeList_NameActionPerformed

    private void jbtSuppTypeList_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSuppTypeList_SubmitActionPerformed
        // TODO add your handling code here:
        boolean checkName = CustomerValidator.checkName(jtfSuppTypeList_Name.getText().trim());
        
            try {
                //Get data
                Suppliers supplierType = new Suppliers();

                supplierType.setSupplierTypeName(jtfSuppTypeList_Name.getText().trim());
                supplierType.setDescription(jtaSuppTypeList_Description.getText().trim());

                //Insert data
                if (flag.equals("insert")) {
                    if (checkName) {
                    
                        if (SupplierTypeManager.checkName(jtfSuppTypeList_Name.getText().trim()) == null) {
                            boolean result = SupplierTypeManager.insert(supplierType);
                            if (result) {
                                JOptionPane.showMessageDialog(this, "Insert Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE);
                                loadData();
                                jdSuppTypeList_InsertUpdate.dispose();
                            } else {
                                JOptionPane.showMessageDialog(this, "Insert Failed!", "Message", JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(this, "Existing Supplier Type Name!", "Message", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        jdSuppList_Notification.setVisible(true);
                        jdSuppList_Notification.pack();

                        ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
                        ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

                        jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
                    }
                } else if (flag.equals("update")){
                    if(checkName){
                        supplierType.setSupplierTypeID
                    (Integer.parseInt(String.valueOf(tableModel.getValueAt(jtbSuppTypeList.getSelectedRow(), 0))));
                        boolean result = SupplierTypeManager.update(supplierType);

                        if (result) {
                            JOptionPane.showMessageDialog(this, "Update Successfully!", "Message", JOptionPane.INFORMATION_MESSAGE);
                            loadData();
                            jdSuppTypeList_InsertUpdate.dispose();
                        } else {
                            JOptionPane.showMessageDialog(this, "Update Failed!", "Message", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        jdSuppList_Notification.setVisible(true);
                        jdSuppList_Notification.pack();

                        ImageIcon correctIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/032.png"));
                        ImageIcon falseIcon = new javax.swing.ImageIcon(getClass().getResource("/com/image/033.png"));

                        jlblStatus_Name.setIcon(checkName ? correctIcon : falseIcon);
                    }
                }
            } catch (SQLException ex) {
                System.err.println(ex.getMessage());
            } catch (Exception ex) {
                Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
            }
    }//GEN-LAST:event_jbtSuppTypeList_SubmitActionPerformed

    private void jbtSuppTypeList_ResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtSuppTypeList_ResetActionPerformed
        // TODO add your handling code here:
        clearForm();
    }//GEN-LAST:event_jbtSuppTypeList_ResetActionPerformed

    private void jbtInsertActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtInsertActionPerformed
        // TODO add your handling code here:
        jdSuppTypeList_InsertUpdate.setVisible(true);
        jdSuppTypeList_InsertUpdate.pack();
        jdSuppTypeList_InsertUpdate.setLocationRelativeTo(null);
        jtfSuppTypeList_Name.setEditable(true);
        flag = "insert";
        clearForm();
    }//GEN-LAST:event_jbtInsertActionPerformed

    private void jbtUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtUpdateActionPerformed
        // TODO add your handling code here:
        flag = "update";
        clearForm();
        if (jtbSuppTypeList.getSelectedRowCount() == 1){
            jdSuppTypeList_InsertUpdate.setVisible(true);
            jdSuppTypeList_InsertUpdate.pack();
            jdSuppTypeList_InsertUpdate.setLocationRelativeTo(null);
         
            try {
                ResultSet resultSet = SupplierTypeManager.displayAllRows();
//                System.out.println(tableModel.getValueAt(jtbSuppTypeList.getSelectedRow(), 0));
                resultSet.absolute(jtbSuppTypeList.getSelectedRow() + 1);
                jtfSuppTypeList_Name.setText(resultSet.getString(2).trim());
            //    jtaSuppTypeList_Description.setText(resultSet.getString(3).trim());
                jtaSuppTypeList_Description.setText(resultSet.getString(3) == null ? "" : resultSet.getString(3).trim());
            } catch(SQLException ex){
                System.err.println(ex.getMessage());
            } catch (Exception ex) {
                Logger.getLogger(SupplierTypeList.class.getName()).log(Level.SEVERE, null, ex);
            }
        }else {
            JOptionPane.showMessageDialog(null, "Please choose a record to update!", "Message",
                    JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbtUpdateActionPerformed

    private void jbtDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtDeleteActionPerformed
        // TODO add your handling code here:
        if (jtbSuppTypeList.getSelectedRowCount() == 1) {
            int reply = JOptionPane.showConfirmDialog(null, "Do you want to delete this record?", "Message",
                    JOptionPane.INFORMATION_MESSAGE);
            if (reply == JOptionPane.YES_OPTION) {
                try {
                    ResultSet resultSet = SupplierTypeManager.displayAllRows();
                    resultSet.absolute(jtbSuppTypeList.getSelectedRow() + 1);
                    resultSet.deleteRow();
                    loadData();
                } catch (SQLException ex) {
                    System.out.println(ex.getMessage());
                } catch (Exception ex) {
                    Logger.getLogger(SupplierList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }else{
            JOptionPane.showMessageDialog(null, "Please choose a record to delete!", "Message", JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jbtDeleteActionPerformed

    /* Clear form */
    private void clearForm(){
        jtfSuppTypeList_Name.setText(null);
        jtaSuppTypeList_Description.setText(null);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(SupplierTypeList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(SupplierTypeList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(SupplierTypeList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(SupplierTypeList.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    new SupplierTypeList().setVisible(true);
                } catch (Exception ex) {
                    Logger.getLogger(SupplierTypeList.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtDelete;
    private javax.swing.JButton jbtInsert;
    private javax.swing.JButton jbtSuppTypeList_Reset;
    private javax.swing.JButton jbtSuppTypeList_Submit;
    private javax.swing.JButton jbtUpdate;
    private javax.swing.JDialog jdSuppList_Notification;
    private javax.swing.JDialog jdSuppTypeList_InsertUpdate;
    private javax.swing.JLabel jlblDescription;
    private javax.swing.JLabel jlblName;
    private javax.swing.JLabel jlblStatus_Description;
    private javax.swing.JLabel jlblStatus_Name;
    private javax.swing.JLabel jlblSuppTypeList_Description;
    private javax.swing.JLabel jlblSuppTypeList_Name;
    private javax.swing.JTextArea jtaSuppTypeList_Description;
    private javax.swing.JTable jtbSuppTypeList;
    private javax.swing.JTextField jtfSuppTypeList_Name;
    // End of variables declaration//GEN-END:variables
}
